package com.example.myapplication10.Activities;

import android.os.Bundle;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication10.DTO.ForecastDTO;
import com.example.myapplication10.DTO.WeatherDTO;
import com.example.myapplication10.MsgEvents.MsgEventForecast;
import com.example.myapplication10.R;
import com.hxc.basemodule.BaseActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

public class ForecastActivity extends BaseActivity {
    FcstRecycleAdapter adapter;
    RecyclerView recyclerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        setContentView(R.layout.activity_forecast);
        setImmersiveWindows();
        showBackButton();
        setTitle("近15日天气");
        recyclerView = findViewById(R.id.forecast15);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(RecyclerView.HORIZONTAL); // 很关键！！！！！！！！！！！！！！！！！！！！！！！！
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
        adapter = new FcstRecycleAdapter();

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void messageWeatherForecastEventBus(MsgEventForecast event) {
        WeatherDTO weather = event.getMsg();
        List<ForecastDTO> forecastList = weather.getData().getForecast();
        adapter.setData(forecastList);
        recyclerView.setAdapter(adapter);
//        ForecastDTO forecastDTO = new ForecastDTO();
//        isLoadOver = true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected int setCurrentLayoutId() {
        return R.layout.activity_forecast;
    }
}